/*
 * Преобразование z-функции в pi-функцию
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#define MEMDEBUG

#define MIN(a, b)	((a) < (b) ? (a) : (b))

/* {{{ memory allocation wrappers */
extern char *
s_calloc(size_t n, size_t size)
{
	void *ptr;
#ifdef MEMDEBUG
	fprintf(stderr, "%s(): calloc %lu times %lu bytes (tot %.4f MiB)\n",
			__func__, n, size, ((float) n * size) / (1024.0f * 1024.0f));
#endif /* MEMDEBUG */
	ptr = calloc(n, size);
	if (ptr == NULL) {
		fprintf(stderr, "%s(): out of memory, failed to allocate %lu bytes\n",
				__func__, n * size);
		abort();
	}
	return ptr;
}

extern char *
s_malloc(size_t size)
{
	void *ptr;
#ifdef MEMDEBUG
	fprintf(stderr, "%s(): malloc %lu bytes (%.4f MiB)\n",
			__func__, size, (float) size / (1024.0f * 1024.0f));
#endif /* MEMDEBUG */
	ptr = malloc(size);
	if (ptr == NULL) {
		fprintf(stderr, "%s(): out of memory, failed to allocate %lu bytes\n",
				__func__, size);
		abort();
	}
	return ptr;
}

extern char *
s_realloc(char *oldptr, size_t newsize)
{
	void *newptr;
#ifdef MEMDEBUG
	fprintf(stderr, "%s(): realloc oldptr %p for new size of %lu (%.4f MiB)\n",
			__func__, oldptr, newsize, (float) newsize / (1024.0f * 1024.0f));
#endif
	newptr = realloc(oldptr, newsize);
	if (newptr == NULL) {
		fprintf(stderr, "%s(): out of memory, "
				"failed to realloc %p for new size of %lu bytes\n",
				__func__, oldptr, newsize);
		abort();
	}
#ifdef MEMDEBUG
	fprintf(stderr, "%s(): newptr %p\n", __func__, newptr);
#endif /* MEMDEBUG */
	return newptr;
}
/* }}} */

int *
z_to_prefix(const int *z, const int len)
{
	int *pref;
	register int i;

	pref = s_calloc(len, sizeof *pref);

	for (i = 1; i < len; i++)
		if (z[i] > pref[i + z[i] - 1])
			pref[i + z[i] - 1] = z[i];
	for (i--; i > 0; i--)
		if (pref[i - 1] < pref[i] - 1)
			pref[i - 1] = pref[i] - 1;

	return pref;
}

int
main(int argc, char **argv)
{
	int len, *s, *p;
	int i;

	scanf("%d", &len);
	s = s_calloc(len, sizeof 1);
	for (i = 0; i < len; i++)
		scanf("%d", s + i);

	p = z_to_prefix(s, len);
	for (i = 0; i < len; i++)
		printf("%d%c", p[i], i + 1 == len ? '\n' : ' ');

	free(p);
	free(s);
	return 0;
}
